package net.zzy.pbbot.plugin.cuit.api;

import net.lz1998.pbbot.bot.Bot;
import net.lz1998.pbbot.bot.BotPlugin;
import net.lz1998.pbbot.utils.Msg;
import net.zzy.pbbot.plugin.cuit.cuitService.CuitService;
import onebot.OnebotEvent;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

/**
 * @author zhuZhaoYang
 * @date 2021/9/24 17:05
 */
@Component
public class Cuit extends BotPlugin {
    @Override
    public int onPrivateMessage(@NotNull Bot bot, @NotNull OnebotEvent.PrivateMessageEvent event) {
        String rawMessage = event.getRawMessage();
        Msg msg = CuitService.getCuitWebsite(rawMessage);
        if (msg != null) {
            msg.sendToFriend(bot, event.getUserId());
        }
        return MESSAGE_IGNORE;
    }

    @Override
    public int onGroupMessage(@NotNull Bot bot, @NotNull OnebotEvent.GroupMessageEvent event) {
        String rawMessage = event.getRawMessage();
        Msg msg = CuitService.getCuitWebsite(rawMessage);
        if (msg != null) {
            msg.sendToGroup(bot, event.getGroupId());
        }
        return MESSAGE_IGNORE;
    }
}
